package com.css.fxfzaqbz.modules.assess.service.impl;

import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.assess.entity.BigSecondDisastersEntity;
import com.css.fxfzaqbz.modules.assess.repository.BigSecondRepository;
import com.css.fxfzaqbz.modules.assess.service.BigSecondService;
import com.css.fxfzaqbz.modules.data.entity.ImportantActivity;
import com.css.fxfzaqbz.modules.data.service.ImportantActivityService;
import com.css.fxfzaqbz.util.PlatformDateUtils;
import com.css.fxfzaqbz.util.PlatformSessionUtils;
import com.css.fxfzaqbz.util.UUIDGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author y1fan
 * @create 2022-09-19 18:13
 */
@Service
public class BigSecondServiceImpl implements BigSecondService {

    @Resource
    private ImportantActivityService importantActivityService;
    @Resource
    private BigSecondRepository bigSecondRepository;


    @Override
    public void saveTask(ImportantActivity importantActivity1) {
        BigSecondDisastersEntity bigSecondDisasters = bigSecondRepository.getBigSecondDisastersByActiveId(importantActivity1.getIaId());
        if (bigSecondDisasters == null) {
            BigSecondDisastersEntity bigSecondDisastersEntity = new BigSecondDisastersEntity();
            bigSecondDisastersEntity.setBsId(UUIDGenerator.getUUID());
            bigSecondDisastersEntity.setContent("次生灾害隐患评估");
            bigSecondDisastersEntity.setBsStatus(YNEnum.N.toString());
            bigSecondDisastersEntity.setBsActiveId(importantActivity1.getIaId());
            bigSecondDisastersEntity.setBsDelFlag(YNEnum.N.toString());
            bigSecondDisastersEntity.setBsCreateTime(PlatformDateUtils.getCurrentTimestamp());
            bigSecondDisastersEntity.setBsCreateUser(PlatformSessionUtils.getUserId());
            bigSecondDisastersEntity.setBsOpinion(importantActivity1.getIaOpinion());
            bigSecondRepository.saveBigSecondDisasters(bigSecondDisastersEntity);
        }

    }

    @Override
    public void upStatus(String id) {
        bigSecondRepository.upStatus(id);
    }
}
